package top.huxy.boot.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.huxy.boot.mapper.ChenyuDao;
import top.huxy.boot.model.entity.Chenyu;
import top.huxy.boot.service.ChenyuService;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @author HuXY
 * @since 2022-01-26 15:34:05
 */
@Service
public class ChenyuServiceImpl implements ChenyuService {
    @Autowired
    public ChenyuDao chenyuDao;

    @Override
    public Chenyu findChenYu(String text) {
        return chenyuDao.findChenYu(text);
    }

    @Override
    public Chenyu getRandomChenyu() {
        int count=chenyuDao.getChenYuCount();
        int index = ThreadLocalRandom.current().nextInt(count);
        return chenyuDao.getChenYuByIndex(index);
    }
}

